package OBJ_Loader;

import graphic.Color;
import graphic.Graphic;
import graphic.TextureBase;
import org.lwjgl.util.vector.Vector3f;
import static graphic.TextureBase.NO_TEX;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
/**
 *  
 * @author Marcin & Bartek
 * 
 * @description Every object in the game`s scene inherit this class. 
 * It defines move, rotations, scaling and importing Models
 * 
 */
public class Object {
    private Model m;
    private Vector3f pos = new Vector3f(0,0,0);
    private Color col = new Color();
    private boolean hasColor = false;
    private Texture tex;
    private Vector3f rot = new Vector3f(0,0,0);
    private float scale=1;
    private boolean reverse=false;
    private boolean mirrorX = false;
    private boolean mirrorY=false;
    private boolean mirrorZ = false;
    private boolean hasTexture = false;
    private boolean dual = false;
    
    public void setDualSide(boolean val){
        setDual(val);        
    }
    public void setMirrorX(boolean val){
        mirrorX=val;
        setReverse(((mirrorX?0:1) + (isMirrorY() ? 0 : 1) + (isMirrorZ() ? 0 : 1)) % 2 == 0);
    }
    public void setMirrorY(boolean val){
        mirrorY=val;
        setReverse(((isMirrorX() ? 0 : 1) + (mirrorY?0:1) + (isMirrorZ() ? 0 : 1)) % 2 == 0);
    }
    public void setMirrorZ(boolean val){
        mirrorZ=val;
        setReverse(((isMirrorX() ? 0 : 1) + (isMirrorY() ? 0 : 1) + (mirrorZ?0:1)) % 2 == 0);
    }
    
    public void setRotate(float x,float y, float z){
        rot.x=x;
        rot.y=y;
        rot.z=z;
    }
    public void setRotateX(float ang){
        rot.x=ang;
    }
    public void setRotateY(float ang){
        rot.y=ang;
    }
    public void setRotateZ(float ang){
        rot.z=ang;
    }
    public void addRotateX(float ang){
        rot.x+=ang;
    }
    public void addRotateY(float ang){
        rot.y+=ang;
    }
    public void addRotateZ(float ang){
        rot.z+=ang;
    }
    
    public void setScale(float s){
        scale=s;
    }
    public void addScale(float s){
        setScale(getScale() + s);
    }
    
    public void setTexture(String file){
        setHasTexture(true);
        setTex(TextureBase.get(file));
    }
    
    public Object(String file, float x, float y, float z){
        m = ModelBase.get(file);
        m.compile();
        pos.x=x;
        pos.y=y;
        pos.z=z;
        tex = NO_TEX;
    }
    public Object(String file, float x, float y, float z,float tx,float ty,float tz){
        m = ModelBase.get(file,tx,ty,tz);
        m.compile();
        pos.x=x;
        pos.y=y;
        pos.z=z;
        tex = NO_TEX;
    }
    public void setColor(float R, float G, float B,float A){
        setHasTexture(false);
        setHasColor(true);
        col.R=R;
        col.G=G;
        col.B=B;
        col.A=A;
    }
    
    public void move(float x, float y, float z){
        pos.x=x;
        pos.y=y;
        pos.z=z;
    }
    public void draw(){
        if(isHasColor()) Graphic.e.setColor(getCol());
        getM().draw(getPos(), getRot(), getScale(), isMirrorX(), isMirrorY(), isMirrorZ(), isReverse(), isDual());
    }

    /**
     * @return the m
     */
    public Model getM() {
        return m;
    }

    /**
     * @param m the m to set
     */
    public void setM(Model m) {
        this.m = m;
    }

    /**
     * @return the pos
     */
    public Vector3f getPos() {
        return pos;
    }

    /**
     * @param pos the pos to set
     */
    public void setPos(Vector3f pos) {
        this.pos = pos;
    }

    /**
     * @return the col
     */
    public Color getCol() {
        return col;
    }

    /**
     * @param col the col to set
     */
    public void setCol(Color col) {
        this.col = col;
    }

    /**
     * @return the hasColor
     */
    public boolean isHasColor() {
        return hasColor;
    }

    /**
     * @param hasColor the hasColor to set
     */
    public void setHasColor(boolean hasColor) {
        this.hasColor = hasColor;
    }

    /**
     * @return the tex
     */
    public Texture getTex() {
        return tex;
    }

    /**
     * @param tex the tex to set
     */
    public void setTex(Texture tex) {
        this.tex = tex;
    }

    /**
     * @return the rot
     */
    public Vector3f getRot() {
        return rot;
    }

    /**
     * @param rot the rot to set
     */
    public void setRot(Vector3f rot) {
        this.rot = rot;
    }

    /**
     * @return the scale
     */
    public float getScale() {
        return scale;
    }

    /**
     * @return the reverse
     */
    public boolean isReverse() {
        return reverse;
    }

    /**
     * @param reverse the reverse to set
     */
    public void setReverse(boolean reverse) {
        this.reverse = reverse;
    }

    /**
     * @return the mirrorX
     */
    public boolean isMirrorX() {
        return mirrorX;
    }

    /**
     * @return the mirrorY
     */
    public boolean isMirrorY() {
        return mirrorY;
    }

    /**
     * @return the mirrorZ
     */
    public boolean isMirrorZ() {
        return mirrorZ;
    }

    /**
     * @return the hasTexture
     */
    public boolean isHasTexture() {
        return hasTexture;
    }

    /**
     * @param hasTexture the hasTexture to set
     */
    public void setHasTexture(boolean hasTexture) {
        this.hasTexture = hasTexture;
    }

    /**
     * @return the dual
     */
    public boolean isDual() {
        return dual;
    }

    /**
     * @param dual the dual to set
     */
    public void setDual(boolean dual) {
        this.dual = dual;
    }
}
